//
//  XCShareMusicTableViewCell.m
//  SoundOfNature
//
//  Created by 梁新昌 on 16/3/8.
//  Copyright © 2016年 梁新昌. All rights reserved.
//

#import "XCShareMusicTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "WDGDatabaseTool.h"
@implementation XCShareMusicTableViewCell

- (void)dealloc {
    [_numberLable release];
    [_nameLable release];
    [_singerNameLable release];
    [_MVButton release];
    [_favoritesLable release];
    [_heartButton release];
    [_picUrlImageView release];
    [_buttonImageView release];
    [_songsModel release];
    [_shareMusicModel release];
    [_newnewSongModel release];
    [_inTheRankSongsModel release];
    [_hotSixSongListModel release];
    [super dealloc];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.numberLable = [[XCBaseLable alloc] initWithFrame:CGRectZero];
        self.singerNameLable = [[XCBaseLable alloc] initWithFrame:CGRectZero];
        self.nameLable = [[XCBaseLable alloc] initWithFrame:CGRectZero];
        self.favoritesLable = [[XCBaseLable alloc] initWithFrame:CGRectZero];
        
        self.heartButton = [UIButton buttonWithType:UIButtonTypeSystem];
        [self.heartButton setImage:[[UIImage imageNamed:@"Image-doubleheart"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
        self.MVButton = [UIButton buttonWithType:UIButtonTypeSystem];
        [self.MVButton setImage:[[UIImage imageNamed:@"Image-MV"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
        
        self.picUrlImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
        self.picUrlImageView.userInteractionEnabled = YES;
        self.buttonImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
        self.buttonImageView.image = [UIImage imageNamed:@"Image-play"];
        self.buttonImageView.userInteractionEnabled = YES;
        
        [self.contentView addSubview:self.buttonImageView];
        [self.contentView addSubview:self.picUrlImageView];
        [self.contentView addSubview:self.MVButton];
        [self.contentView addSubview:self.heartButton];
        
        [self.contentView addSubview:self.nameLable];
        [self.contentView addSubview:self.singerNameLable];
        [self.contentView addSubview:self.favoritesLable];
        [self.contentView addSubview:self.numberLable];
        
        [_numberLable release];
        [_nameLable release];
        [_singerNameLable release];
        [_favoritesLable release];
        [_picUrlImageView release];
        [_buttonImageView release];
    }
    return self;
}
- (void)layoutSubviews {
    [super layoutSubviews];
    self.numberLable.frame = CGRectMake(10, self.bounds.size.height / 2 - 10, 25, 15);
    self.numberLable.font = [UIFont systemFontOfSize:13];
    self.picUrlImageView.frame = CGRectMake(45, 7.5, self.bounds.size.height - 15, self.bounds.size.height - 15);
    
    self.nameLable.frame = CGRectMake(35 + self.bounds.size.height, 0, self.bounds.size.width / 3 , 30);
    self.nameLable.font = [UIFont systemFontOfSize:14];
    self.singerNameLable.frame = CGRectMake(35 + self.bounds.size.height, self.bounds.size.height / 2 , self.bounds.size.width / 6, 30);
    self.singerNameLable.font = [UIFont systemFontOfSize:13];
    self.singerNameLable.textColor = [UIColor colorWithRed:0.6 green:0.6 blue:0.6 alpha:1.0];
    self.heartButton.frame = CGRectMake(35 + self.bounds.size.height + self.bounds.size.width / 6, self.bounds.size.height / 2 + 5, 20, 20);
    self.favoritesLable.frame = CGRectMake(60 + self.bounds.size.height + self.bounds.size.width / 6, self.bounds.size.height / 2 , self.bounds.size.width / 6, 30);
    self.favoritesLable.font = [UIFont systemFontOfSize:10];
    self.favoritesLable.textColor = [UIColor colorWithRed:0.9927 green:0.6385 blue:0.0416 alpha:1.0];
    
    self.buttonImageView.frame = CGRectMake(self.bounds.size.width - 50, self.bounds.size.height / 2 - 20 , 40, 40);
    
    for (NSDictionary *dic in self.songsModel.mvList) {
        if (dic[@"url"]) {
            self.MVButton.frame = CGRectMake(self.nameLable.frame.size.width + self.frame.origin.x + 100, self.bounds.size.height / 2 - 40, 40, 35);
        } else {
            self.MVButton.frame = CGRectMake(0, 0, 0, 0);
        }
    }
    
    
}

- (void)setSongsModel:(XCSongsModel *)songsModel {
    if (_songsModel != songsModel) {
        [_songsModel release];
        _songsModel = [songsModel retain];
    }
    _songsModel = songsModel;
    [self.picUrlImageView sd_setImageWithURL:[NSURL URLWithString:songsModel.picUrl]];
    self.singerNameLable.text = songsModel.singerName;
    self.nameLable.text = songsModel.name;
    if (songsModel.favorites.intValue > 9999) {
        float a = songsModel.favorites.floatValue / 10000;
        self.favoritesLable.text = [NSString stringWithFormat:@"%.1f万", a];
    } else {
        self.favoritesLable.text = [NSString stringWithFormat:@"%d", songsModel.favorites.intValue];
    }
    

}

- (void)setShareMusicModel:(XCShareMusicMoidel *)shareMusicModel {
    if (_shareMusicModel != shareMusicModel) {
        [_shareMusicModel release];
        _shareMusicModel = [shareMusicModel retain];
    }
    self.nameLable.text = shareMusicModel.name;
    self.singerNameLable.text = shareMusicModel.singerName;
    [self.picUrlImageView sd_setImageWithURL:[NSURL URLWithString:shareMusicModel.picUrl]placeholderImage:[UIImage imageNamed:@"Image-p"]];
    
}
- (void)setInTheRankSongsModel:(XCInTheRankSongsModel *)inTheRankSongsModel {
    if (_inTheRankSongsModel != inTheRankSongsModel) {
        [_inTheRankSongsModel release];
        _inTheRankSongsModel = [inTheRankSongsModel retain];
    }
    self.nameLable.text = inTheRankSongsModel.name;
    self.singerNameLable.text = inTheRankSongsModel.singerName;
    [self.picUrlImageView sd_setImageWithURL:[NSURL URLWithString:inTheRankSongsModel.picUrl]placeholderImage:[UIImage imageNamed:@"Image-p"]];
    
}
- (void)setInTheSongListModel:(XCInTheSongListModel *)inTheSongListModel {
    if (_inTheSongListModel != inTheSongListModel) {
        [_inTheSongListModel release];
        _inTheSongListModel = [inTheSongListModel retain];
    }
    self.nameLable.text = inTheSongListModel.name;
    self.singerNameLable.text = inTheSongListModel.singerName;
    [self.picUrlImageView sd_setImageWithURL:[NSURL URLWithString:inTheSongListModel.picUrl]placeholderImage:[UIImage imageNamed:@"Image-p"]];
    
}
- (void)setInTheRadioDataModel:(XCInTheRadioDataModel *)inTheRadioDataModel {
    if (_inTheRadioDataModel != inTheRadioDataModel) {
        [_inTheRadioDataModel release];
        _inTheRadioDataModel = [inTheRadioDataModel retain];
        
    }
    
    self.nameLable.text = inTheRadioDataModel.song_name;
    self.singerNameLable.text = inTheRadioDataModel.singer_name;
    [self.picUrlImageView sd_setImageWithURL:[NSURL URLWithString:[inTheRadioDataModel.mv_list[0] objectForKey:@"picUrl"]]placeholderImage:[UIImage imageNamed:@"Image-p"]];
    
    
}
- (void)setHotSixSongListModel:(XCHotSixSongListModel *)hotSixSongListModel {
    if (_hotSixSongListModel != hotSixSongListModel) {
        [_hotSixSongListModel release];
        _hotSixSongListModel = [hotSixSongListModel retain];
    }
    self.nameLable.text = hotSixSongListModel.name;
    self.singerNameLable.text = hotSixSongListModel.singerName;
    [self.picUrlImageView sd_setImageWithURL:[NSURL URLWithString:hotSixSongListModel.picUrl]placeholderImage:[UIImage imageNamed:@"Image-p"]];
    
    
}

- (void)setSearchModel:(XCSearchModel *)searchModel {
    if (_searchModel != searchModel) {
        [_searchModel release];
        _searchModel = [searchModel retain];
    }
    self.nameLable.text = searchModel.name;
    self.singerNameLable.text = searchModel.singerName;
    [self.picUrlImageView sd_setImageWithURL:[NSURL URLWithString:searchModel.picUrl]placeholderImage:[UIImage imageNamed:@"Image-p"]];
    self.favoritesLable.text = [NSString stringWithFormat:@"%@", searchModel.favorites];
    
}
- (void)setXcnewMVModel:(XCNewMVModel *)xcnewMVModel {
    if (_xcnewMVModel != xcnewMVModel) {
        [_xcnewMVModel release];
        _xcnewMVModel = [xcnewMVModel retain];
    }
    self.nameLable.text = xcnewMVModel.songName;
    self.singerNameLable.text = xcnewMVModel.singerName;
    XCNewMVListModel *xcNewListModel = xcnewMVModel.mvList[0];
    [self.picUrlImageView sd_setImageWithURL:[NSURL URLWithString:xcNewListModel.picUrl] placeholderImage:[UIImage imageNamed:@"Image-p"]];
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
